package com.yjd.back.app;

import com.yjd.comm.app.model.PushRecordModel;
import com.yjd.comm.app.service.IPushRecordService;
import com.yjd.comm.base.control.BaseControl;
import com.yjd.comm.base.enums.DbWREnums;
import com.yjd.comm.base.model.PagerHtmlModel;
import com.yjd.comm.util.DateUtil;
import com.yjd.comm.util.PagerUtil;
import com.yjd.comm.util.ServletUtil;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.Map;

/**
 * 推送记录管理
 * Created by yangchangyan on 2017/8/17.
 */
@Controller("com.yjd.back.app.PushRecordControl")
@Scope("prototype")
@RequestMapping("/push")
public class PushRecordControl extends BaseControl {

    @Resource
    private IPushRecordService pushRecordService;

    @RequestMapping(value = "/all")
    public String allVersion() throws Exception {

        Map<String, Object> paramMap = ServletUtil.getParameterMap(request);
        paramMap.put("rows", "20");
        paramMap.put("sort", " create_time desc ");
        PagerHtmlModel pager = PagerUtil.getPagerHtmlModel(
                this.pushRecordService.getPageModel(paramMap, DbWREnums.READ), paramMap,
                ServletUtil.getUrl("/push/all"));

        PushRecordModel prm = null;
        for (Object obj : pager.getPagerModel().getDataList()) {
            prm = (PushRecordModel) obj;
            prm.getStrMap().put("create_time", DateUtil.timestampToDateString(prm.getCreate_time(), DateUtil.PATTERN_yyyy_MM_dd_HH_mm_ss));
            prm.getStrMap().put("last_update_time", DateUtil.timestampToDateString(prm.getUpdate_time(), DateUtil.PATTERN_yyyy_MM_dd_HH_mm_ss));
        }

        request.setAttribute("maps", paramMap);
        request.setAttribute("pager", pager);

        return "push.all";
    }
}
